home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / fplib20 / pow.c < prev    next >
C/C++ Source or Header  |  1990-11-23  |  767b  |  34 lines

  1. /* POW function for Sozobon C.                        */
  2. /* Copyright © David Brooks, 1989 All Rights Reserved            */
  3. /*                                    */
  4. /* This uses exp and log in the obvious way.  A domain error occurs if    */
  5. /* a=0 and p<=0, or a<0 and p is not integral.                */
  6.  
  7. #include <fplib.h>
  8. #include <errno.h>
  9.  
  10. float pow(a, p)
  11. fstruct a, p;
  12. {    fstruct        r;
  13.     register long    pint;
  14.     register int    sign = 0;
  15.  
  16.     if (a.sc[3] == 0 && p.sc[3] <= 0)
  17.     {    errno = EDOM;
  18.         return 0.0;
  19.     }
  20.  
  21.     if (a.sc[3] < 0)        /* ...if a.f < 0 */
  22.     {    pint = (long)p.f;
  23.         if ((float)pint != p.f)    /* ... if nonintegral */
  24.             errno = EDOM;
  25.         sign = pint & 1;    /* ... carry on regardless */
  26.         a.sc[3] &= EXP_MASK;
  27.     }
  28.  
  29.     r.f = exp(log(a.f) * p.f);
  30.     if (sign && (r.sc[3] != 0))
  31.         r.sc[3] |= 0x80;
  32.     return r.f;
  33. }
  34.